// 这里封装自定义Link
import React, { Component, createElement } from "react";
import { withRouter } from "react-router-dom";
@withRouter
class Mylink extends Component {
  goto = (to) => {
    this.props.history.push(to);
  };
  render() {
    const { tag, to, className } = this.props;
    // createElement 创建自定义动态标签，第一个参数是标签类型，第二个是属性，第三个是内容
    return (
      <>
        {createElement(
          tag,
          {
            onClick: () => this.goto(to),
            className: className,
          },
          [this.props.children]
        )}
      </>
    );
  }
}
export default Mylink;
